<?php 
defined('IN_SITE') or exit('Access Denied');

require_once 'search.class.php';
$search = new search();
require_once 'type.class.php';
$t = new type();
if(!$forward) $forward = HTTP_REFERER;

switch($action)
{
	case 'setting':
		if($dosubmit)
		{
			if($setting['ishtml'] == 1)
			{
				$setting['type_urlruleid'] = $setting['type_urlruleid_1'];
				$setting['show_urlruleid'] = $setting['show_urlruleid_1'];
			}
			else
			{
				$setting['type_urlruleid'] = $setting['type_urlruleid_0'];
				$setting['show_urlruleid'] = $setting['show_urlruleid_0'];
			}
			unset($setting['type_urlruleid_1'], $setting['show_urlruleid_1'], $setting['type_urlruleid_0'], $setting['show_urlruleid_0']);
			module_setting($module, $setting);
			showmessage($LANG['save_setting_success'], HTTP_REFERER);
		}
		else
		{
			@extract(new_htmlspecialchars($M));
			if(!isset($ishtml)) $ishtml = $SETTING['ishtml'];
			include ('setting');
		}
		
    case 'type_add':
		if($dosubmit)
		{
			$result = $t->add($type, $name, $md5key, $description);
			if($result)
			{
				showmessage('操作成功！', $forward);
			}
			else
			{
				showmessage('操作失败！');
			}
		}
		else
		{
			include ('type_add');
		}
		break;
    case 'type_edit':
		if($dosubmit)
		{
			$result = $t->edit($type, $name, $md5key, $description);
			if($result)
			{
				showmessage('操作成功！', $forward);
			}
			else
			{
				showmessage('操作失败！');
			}
		}
		else
		{
			$r = $t->get($type);
			if(!$r) showmessage('指定的类别不存在！');
			extract($r);
			include ('type_edit');
		}
		break;
    case 'type_manage':
		$page = max(intval($page), 1);
		$pagesize = max(intval($pagesize), 20);
        $infos = $t->listinfo($page, $pagesize);
		include ('type_manage');
		break;
    case 'type_delete':
		$result = $t->delete($typeid);
		if($result)
		{
			showmessage('操作成功！', $forward);
		}
		else
		{
			showmessage('操作失败！');
		}
		break;
    case 'type_listorder':
		$result = $t->listorder($info);
		if($result)
		{
			showmessage('操作成功！', $forward);
		}
		else
		{
			showmessage('操作失败！');
		}
		break;
	case 'type_check':
        echo $t->check($value) ? 'success' : $t->errormsg();
		break;
		
    default :
		if($dosubmit)
		{
			$search->create_index();
			showmessage('全文索引重建成功！', $forward);
		}
		else
		{
			$inifile = substr(PHP_OS, 0, 3) == 'WIN' ? 'my.ini' : 'my.cnf';
			include ('search_createindex');
		}
		break;
}
?>